<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--sweetalert2-->
    <link href="./sweetalert2/dist/sweetalert2.min.css" rel="stylesheet">
    <script src="./sweetalert2/dist/sweetalert2.min.js" type="text/javascript"></script>
</head>
<body>


<script>



    async  function fn(){
        const ipAPI = './json/2.txt'

        const inputValue = fetch(ipAPI)
            .then(function (response){
                return response.json();
            })                                    //response => response.json()
            .then(data => data.ip)

        const { value: ipAddress } = await Swal.fire({
            title: 'Enter your IP address',
            input: 'text',
            inputLabel: 'Your IP address',
            inputValue: inputValue,
            showCancelButton: true,

            inputValidator: (value) => {
                if (!value) {
                    return 'You need to write something!'
                }
            }
        })

        console.log(p.value)

        if (p.value) {         //任何字符串除了空 都是 true
            Swal.fire(`Your IP address is ${p.value}`)
        }else{
            alert('false')
        }
    }


    fn()
</script>
</body>
</html>